package handlers

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func GetRecordsHandler(c *gin.Context) {
	name := c.DefaultQuery("name", "")
	fmt.Println("name:>>> ", name)
	// 模拟根据name获取values,实际业务中可能会从数据库中获取...
	currMap := map[string][]string{
		"whw":    []string{"aaa", "bbb", "ccc"},
		"naruto": []string{"c12", "b67", "na2"},
		"sasuke": []string{"bnv", "cxz", "kiu"},
	}
	vs, ok := currMap[name]
	if !ok {
		c.JSONP(http.StatusBadRequest, nil)
		return
	}
	service := serviceStruct{
		Name:   name,
		Values: vs,
	}
	ret, err := service.handleRecordsService()
	if err != nil {
		c.JSONP(http.StatusBadRequest, nil)
		return
	}
	c.JSON(http.StatusOK, ret)
}
